home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12717 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  69 lines

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help!  Can't read input from keyboard!
  5. Date: Tue, 02 Apr 96 11:15:03 GMT
  6. Organization: none
  7. Distribution: world
  8. Message-ID: <828443703snz@genesis.demon.co.uk>
  9. References: <4jq0ts$5mh@taniemarie.solon.com> <1APR199622404442@erich.triumf.ca>
  10. Reply-To: fred@genesis.demon.co.uk
  11. X-NNTP-Posting-Host: genesis.demon.co.uk
  12. X-Newsreader: Demon Internet Simple News v1.27
  13. X-Mail2News-Path: genesis.demon.co.uk
  14.  
  15. In article <1APR199622404442@erich.triumf.ca>
  16.            bennett@erich.triumf.ca "P.Bennett" writes:
  17.  
  18. >In article <4jq0ts$5mh@taniemarie.solon.com>, seebs@taniemarie.solon.com (Peter
  19. > Seebach) writes...
  20. >>I guess I thought I knew C, but maybe not.  The following program compiles
  21. >>without error with
  22. >>
  23. >>gcc -g -O -Wa,ll -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes
  24. > -Wmissing-prototypes
  25.  
  26. Remarkable.
  27.  
  28. >>but doesn't print 3!  I thought scanf and printf were asymptotic.
  29.  
  30. You were definitely thinking of cosh()
  31.  
  32. >It would help if you posted the _real_ code so we would know there weren't any
  33. >typos...
  34. >
  35. >>       #include <stdio.h>
  36. >> 
  37. >>       int main(void) {
  38. >>               int i = 0;
  39. >> 
  40. >>               (void) sscanf, "3", "%d", i;
  41. >
  42. >This won't compile as is - it needs some parentheses, like:
  43.  
  44. Try it, it is perfectly valid code.
  45.  
  46. >                (void) sscanf("3", "%d", i);
  47. >If this is what your real code says, then you need to change it to:
  48. >                (void) sscanf("3", "%d", &i);
  49. >Since sscanf() must change i, you have to pass i's _address_, using &i.
  50. >
  51. >
  52. >> 
  53. >>               (void) printf, "%d", i;
  54. >this must have some parentheses as well:
  55. >                (void) printf("%d", i);
  56. >
  57. >The arguments for the sscanf() and printf() families are similar, but not
  58. >identical - scanf() needs the _address_ of its arguments, and printf() does
  59. >not.  There are also some differences in the format specifiers.
  60.  
  61. April Fools are supposed to be perpetrated before noon, Mr Seebach!
  62.  
  63.  
  64. -- 
  65. -----------------------------------------
  66. Lawrence Kirby | fred@genesis.demon.co.uk
  67. Wilts, England | 70734.126@compuserve.com
  68. -----------------------------------------
  69.